<?php

namespace App\B2BProject\Admin\Authority\Rbac;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
    protected $fillable = ['name', 'display_name', 'description'];

    public static function boot()
    {
        parent::boot();

        static::deleting(function($permission) {
            if (!method_exists(Permission::class, 'bootSoftDeletingTrait')) {
                $permission->roles()->sync([]);
            }

            return true;
        });
    }

    public function roles()
    {
        return $this->belongsToMany('App\B2BProject\Admin\Authority\Rbac\Role');
    }
}
